package com.hrma.controller;

import com.github.pagehelper.Page;
import com.hrma.entity.*;
import com.hrma.services.TravelRecordService;
import com.hrma.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/travelRecord")
@Slf4j
public class TravelRecordController {
    private final TravelRecordService travelRecordService;

    public TravelRecordController(TravelRecordService travelRecordService) {
        this.travelRecordService = travelRecordService;
    }

    @PostMapping("/add")
    public Result<TravelRecordVO> add(@RequestBody TravelRecordVO data){
        log.debug("收到add请求，请求参数：{}", data);
        return Result.ok(travelRecordService.add(data));
    }

    @GetMapping("/select")
    public Result<List<SelectResult>> select() {
        log.debug("收到select请求！");
        return Result.ok(travelRecordService.select());
    }

    @PostMapping("/list")
    public Result<ListWithCount<TravelRecordVO>> getList(@RequestBody TravelRecordDTO data) {
        log.debug("收到list请求，请求参数：{}", data);
        Page<TravelRecordVO> res = travelRecordService.getList(data);
        return Result.ok(new ListWithCount<>(res.getTotal(), res));
    }

    @PostMapping("/personalList")
    public Result<ListWithCount<TravelRecordVO>> getPersonalList(@RequestBody TravelRecordDTO data) {
        log.debug("收到list请求，请求参数：{}", data);
        Page<TravelRecordVO> res = travelRecordService.getPersonalList(data);
        return Result.ok(new ListWithCount<>(res.getTotal(), res));
    }
}
